﻿using System;
using System.Windows;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCommon.ChildWindows;

namespace Baosight.ZNH.ZMCM.UI.ChildWindows
{
    public partial class MaterialBase : EFViewCmes
    {
        public MaterialBase(string dialogType)
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
            Init(dialogType);     
        }
    
        /// <summary>
        /// 初始化父类EFViewCmesProperty的值，每次点击“确定”、“返回”时执行此方法，从新赋值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.spWindows.GetChildObjects<EFDataField>(null, true);
            base.ViewProperty = _view;
        }

        /// <summary>
        /// 初始化页面数据
        /// </summary>
        private void Init(string type)
        {
            type = type == null ? "insert" : type.ToLower();

            switch (type)
            {
                case "insert":
                    base.Mode = OperationMode.Insert;
                    break;
                case "update"://设置安全库存
                    base.Mode = OperationMode.Update;

                    this.fdDepotName.IsEnabled = false;//库房名称不可编辑
                    this.fdMaterialCode.IsEnabled = false;//物资编码不可编辑
                    this.fdMaterialName.IsEnabled = false;//物资名称不可编辑
                    
                    this.fdMetric.IsEnabled = false;//计量单位不可编辑
                    this.fdQuality.IsEnabled = false;//材质不可编辑
                    this.fdSpecModel.IsEnabled = false;//规格型号不可编辑

                    this.fdNumber.IsEnabled = false;//图号不可编辑
                    this.fdPrice.IsEnabled = false;//单价不可编辑
                    this.fdNum.IsEnabled = false;//数量不可编辑

                    break;
                case "detail":
                    this.Commit.Visibility = Visibility.Collapsed;
                    BaseTools.EFDataFieldNotEnabled(this.spWindows.GetChildObjects<EFDataField>(null, true));
                    break;
                default:
                    break;
            }
        }
        
        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommitClick(object sender, RoutedEventArgs e)
        {
            base.OnCommitButtonClick("ZMCM90", sender, e);
        }

        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelClick(object sender, RoutedEventArgs e)
        {
            CmesWindows _window = this.Parent as CmesWindows;
            _window.DialogResult = false;
            _window.Close();
        }    
    

    }
}
